﻿using System;
using System.Data;
using System.Web.UI;
using Solution.BusinessObject;

namespace Solution.CMS
{
    public partial class Login : Page
    {
        public string RedirectedUri { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("/CMS");
        }

        protected void btnLogIn_Click(object sender, EventArgs e)
        {
            var passwordEncrypt = Login1.Password.Trim();
            if (string.IsNullOrEmpty(passwordEncrypt))
            {
                return;
            }

            passwordEncrypt = CommonBO.EncryptMD5(passwordEncrypt);

            DataSet ds = new DataSet();
            ds.ReadXml(Server.MapPath("/CMS/users.xml"));

            if (ds.Tables.Count <= 0) return;
            if (ds.Tables[0].Rows[0]["username"].ToString() == Login1.UserName.Trim() &&
                ds.Tables[0].Rows[0]["password"].ToString() == passwordEncrypt)
            {
                Session["user"] = Login1.UserName;
                Response.Redirect("/CMS");
            }
        }
    }
}